package org.javia.animalfarm;

import android.content.Context;
import android.text.Layout;
import android.widget.Button;
import android.view.Gravity;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AnimalView extends LinearLayout {
	TextView count;
	ImageButton animal;
	Button buyLeft, buyRight;
	
	public AnimalView(Context context, int i, int icon) {
		super(context);
		setOrientation(VERTICAL);
		LayoutParams layout  = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		LayoutParams layout2 = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT);
		layout2.weight = 1;
		
		count = new TextView(context);
		count.setText("" + i);
		count.setGravity(Gravity.CENTER);
		addView(count, layout);
		
		animal = new ImageButton(context);
		animal.setImageResource(icon);
		addView(animal, layout);
		
		buyLeft  = createButton(context, "\u00bb");		
		buyRight = createButton(context, "\u00ab");
		
		LinearLayout buttons = new LinearLayout(context);
		buttons.setOrientation(HORIZONTAL);
		buttons.addView(buyLeft, layout2);
		buttons.addView(buyRight, layout2);
		
		addView(buttons, layout);
	}
	
	private Button createButton(Context context, String txt) {
		Button b = new Button(context);
		b.setText(txt);
		b.setMinLines(2);
		b.setGravity(0x10); //center_vertical
		b.setGravity(Gravity.CENTER);
		return b;
	}
}
